package com.changgou.system;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class);
    }

    @Bean//可以通过KeyResolver来指定限流的Key,比如我们需要根据用户来做限流，IP来做限流等等。
    public KeyResolver ipKeyResolver(){
           return new KeyResolver() {
               @Override
               //此处为根据限制ip访问
               public Mono<String> resolve(ServerWebExchange exchange) {
                   return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
               }
           };
    }
}
